home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: cix.compulink.co.uk!usenet
- From: henri@cix.compulink.co.uk ("Henry Andrew")
- Subject: Re: two tricky questions
- Message-ID: <DKv098.7JE@cix.compulink.co.uk>
- Organization: Compulink Information eXchange
- References: <4cnan0$gqv@news.xmission.com>
- Date: Mon, 8 Jan 1996 11:07:55 GMT
- X-News-Software: Ameol32
-
- Umm . . .
- It could be that some compilers do it as a bitwise copy but the compiler
- I am currently using (IBM CSet++ on AIX) does a memberwise copy.
- And in so doing, it seems to me, follow Stroustrup.
-
- Try the following code:
- #include <iostream.h>
- class B { public:
- int _i;
- B(const B & b) { _i = b._i + 1;}
- B(int i=10) : _i(i) {}};
-
- class A { public: B _b;
- A(int 1=20) : _b(i) {}};
-
- void main(void)
- {
- A a1;
- A a2(a1);
- cout << a1._b._i << '\t' << a2._b._i << endl;
- }
-
- mine prints "20 21"
- a default copy of the bitmap would give "20 20"
-
- Refs.
-
- Grey book
- r.12.8
- ". . . If not defined by the programmer, they will be defined as
- memberwise assignment and memberwise initialization of the members of X,
- respectively."
-
- and (somewhat to my surprise)
-
- ARM
- 12.8
- ". . . If not defined by the programmer, they will be defined as
- memberwise assignment and memberwise initialization of the members of X,
- respectively."
-
- Yours &c. Henry
-